package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.ChildCompanyAddDTO;
import org.jsola.hr.dto.ChildCompanyUpdateDTO;
import org.jsola.hr.entity.ChildCompanyDO;
import org.jsola.hr.query.ChildCompanyQuery;
import org.jsola.hr.service.IChildCompanyService;
import org.jsola.hr.vo.ChildCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 用工单位分组
 *
 * @author zhr
 */
@Component
public class ChildCompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private IChildCompanyService childCompanyService;

    /**
     * 生成add测试数据
     * @return ChildCompanyAddDTO
     */
    public ChildCompanyAddDTO getChildCompanyAddDTO(){
        ChildCompanyAddDTO childCompanyAddDTO = new ChildCompanyAddDTO();
        childCompanyAddDTO.setName(getRandomValue("varchar",255));
        childCompanyAddDTO.setAddress(getRandomValue("varchar",255));
        childCompanyAddDTO.setParentId(getRandomValue("varchar",32));
        childCompanyAddDTO.setSort(SafeKit.getLong(getRandomValue("bigint",10)));
        childCompanyAddDTO.setLevel(SafeKit.getInteger(getRandomValue("int",10)));
        return childCompanyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ChildCompanyUpdateDTO
     */
    public ChildCompanyUpdateDTO getChildCompanyUpdateDTO(ChildCompanyVO childCompanyVO){
        return childCompanyService.selectDOById(childCompanyVO.getId(), SITE_ID).to(ChildCompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ChildCompanyQuery
     */
    public ChildCompanyQuery getChildCompanyQuery() {
        ChildCompanyQuery childCompanyQuery = new ChildCompanyQuery();
        List<ChildCompanyDO> childCompanyDOList = childCompanyService.list(new ChildCompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(childCompanyDOList)) {
            ChildCompanyDO childCompanyDO = childCompanyDOList.get(0);
            childCompanyQuery = childCompanyDO.to(ChildCompanyQuery.class);
        }
        return childCompanyQuery;
    }

    /**
     * 保存示例
     * @return ChildCompanyVO
     */
    public ChildCompanyVO saveChildCompanyExample(){
        ChildCompanyAddDTO addDTO = this.getChildCompanyAddDTO();
        ChildCompanyVO childCompanyVO = childCompanyService.save(addDTO,buildTokenUser());
        return childCompanyVO;
    }


}

